const axios = require('axios');

const api = {};

/**
 * 创建商品接口
 * @param data
 * @param option
 */
api.create = function (data, option) {
    axios.post('/api/goods/create.do',data).then(function (response) {
        if(response.data.error === 0){
            if('success' in option)
                option.success(response.data.data);
        } else {
            if('fail' in option)
                option.fail(response.data.message);
        }
        if('complete' in option)
            option.complete();
    }).catch(function (error) {
        if('error' in option)
            option.error(error);
        if('complete' in option)
            option.complete();
    });
};

api.list = function (args,option) {
    axios.get('/api/goods/list.ajax', {
        params: args
    }).then(function (response) {
        if(response.data.error === 0){
            if('success' in option)
                option.success(response.data.data);
        } else {
            if('fail' in option)
                option.fail(response.data.message);
        }
    }).catch(function (error) {
        if('error' in option)
            option.error(error);
    });
};

export default api;